package com.bll;

import java.util.ArrayList;

import com.dal.ProductTypeDAO;
import com.model.ProductType;

public class ProductTypeBLO {
	public enum ProductTypeEnum {
		Coding(1), Syntax(2);

		private final int id;

		ProductTypeEnum(int i) {
			id = i;
		}

		ProductTypeEnum parse(int i) throws Exception {
			for (ProductTypeEnum e : ProductTypeEnum.values()) {
				if (e.id == id) {
					return e;
				}
			}
			return null;
		}
	}

	private int productTypeId;
	private String productTypeName;

	public ProductTypeBLO(int ProductTypeId, String ProductTypeName) {
		super();
		this.productTypeId = ProductTypeId;
		this.productTypeName = ProductTypeName;
	}

	// Methods

	public static ArrayList<ProductTypeBLO> loadAllProductType() {
		ArrayList<ProductType> list = new ProductTypeDAO().select();
		return getProductTypeBLOListFromEntityList(list);
	}

	// Internal Methods
	private static ArrayList<ProductTypeBLO> getProductTypeBLOListFromEntityList(
			ArrayList<ProductType> list) {
		ArrayList<ProductTypeBLO> ProductTypeBLOlist = new ArrayList<ProductTypeBLO>();
		for (ProductType ProductType : list) {
			ProductTypeBLOlist.add(getProductTypeBLOFromEntity(ProductType));
		}
		return ProductTypeBLOlist;
	}

	private static ProductTypeBLO getProductTypeBLOFromEntity(ProductType entity) {
		return new ProductTypeBLO(entity.getProductTypeID(), entity.getProductTypeName());
	}

	// Utility Methods
	public String getDisplayText() {
		return productTypeName;
	}

	/**
	 * @return the ProductTypeId
	 */
	public int getProductTypeId() {
		return productTypeId;
	}

	/**
	 * @param ProductTypeId
	 *            the ProductTypeId to set
	 */
	public void setProductTypeId(int ProductTypeId) {
		this.productTypeId = ProductTypeId;
	}

	/**
	 * @return the ProductTypeName
	 */
	public String getProductTypeName() {
		return productTypeName;
	}

	/**
	 * @param ProductTypeName
	 *            the ProductTypeName to set
	 */
	public void setProductTypeName(String ProductTypeName) {
		this.productTypeName = ProductTypeName;
	}

}
